//
// Created by jack on 2021/2/2.
//

#ifndef WEILACSDK_WEILAPB_DECFUNS_H
#define WEILACSDK_WEILAPB_DECFUNS_H

typedef struct _PB_FILED_DATA {
    PB_INT16 dataType;
    PB_INT16 dataSize;
    PB_INT16 maxSize;
    PB_INT16 subMsgSize;
    void*    pData;
    void* (*decSubMsg)(pb_istream_t* stream, const pb_field_t* field);
    PB_BOOL (*encSubMsg)(pb_ostream_t* stream, const pb_field_t* field, const void* pData);
} PBFieldData;

typedef bool (*decodeCallback)(pb_istream_t* stream, const pb_field_t* field, void** arg);
typedef bool (*encodeCallback)(pb_ostream_t* stream, const pb_field_t* field, void* const* arg);

extern void    weilapb_setDecCallback(PBFieldData* pFieldData, pb_callback_t* pCallback, decodeCallback callback);
extern void    weilapb_setEncCallback(PBFieldData* pFieldData, pb_callback_t* pCallback, encodeCallback callback);
extern void    weilapb_initDecDataItem(PBFieldData* pFiledData, PB_INT16 dataType, PB_INT32 maxDataSize, void* pData);
extern void    weilapb_initEncDataItem(PBFieldData* pFiledData, PB_INT16 dataType, PB_INT32 dataSize, void* pData);
extern PB_BOOL weilapb_decodeWeilaMsg(PBWeilaMsg* pWeilaMsg, pb_istream_t* pbIstream, void* serviceMsgData);
extern PB_BOOL weilapb_encodeWeilaMsg(void* serviceMsgData, PBEncResult* pEncResult);
extern void*   weilapb_buildServiceMsg(PB_UINT32 serviceId, PB_UINT32 commandId, PB_UINT32 commandType);
extern PBWeilaMsg* weilapb_decodeEmptyRsp(const PB_UINT8* pData, PB_UINT32 dataSize);
extern void        weilapb_freePBLinkList(PBLinkList* pLinkList);
extern void        weilapb_addRecyclePointer(PBWeilaMsg* pPbWeilaMsg, PB_UINT32 ptrType, void* ptr);
extern void        weilapb_freeMsgDataLink(PBLinkList* pList);
#endif  // WEILACSDK_WEILAPB_DECFUNS_H
